<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%
	String path = request.getContextPath() + "/";
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>读者中心</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/reveal.css">
<script src="js/jquery-1.9.1.js"></script>
<link rel="stylesheet" href="css/bootstrap.css">
<script src="js/layer/layer.js"></script>
<script src="js/jwplayer.js"></script>
<script src="js/page.js"></script>
</head>
<body>
	<!--主体-->
	<div class="main ">
		<jsp:include page="head.jsp"></jsp:include>
		<div class="tableMain">
			<div class="table-responsive">
				<table class="table table-striped table-hover table-bordered">
					<thead>
						<tr>
							<th>设备</th>
							<th>视频</th>
							<th>围观次数</th>
							<th>朗读时间</th>
							<th>功能</th>
						</tr>
					</thead>
					<tbody id="list">
					</tbody>
				</table>
			</div>
			<!--播放 视频-->
			<div id="myModal" class="reveal-modal">
			</div>
			<!--播放 视频结束-->

			<!--分页-->
			<div class="tcdPageCode">
				
			</div>
		</div>
		<!--表格结束-->
	</div>
	<div class="footer">信昇达朗读亭</div>
	<script>
	var thePlayer;
		function playVedio(url){
			var media1 = '<a class="close-reveal-modal" onclick="closeModal();">&#215;</a><div id="vd"></div>';
			$('#myModal').html(media1);
			$('#myModal').css("visibility","visible");
			thePlayer = jwplayer('vd').setup({  
		        'flashplayer': 'jwplayer.flash.swf',  
		        'file': url,  
		        'width': '600',  
		        'height': '450'
		      });
		}
		function closeModal(){
			location.reload();
			//$('#myModal').html("");
			//$('#myModal').css("visibility","hidden");
		}
$(document).ready(function() {
	searchList(1);
});
function searchList(pageNo){
	$("#pageNo").val(pageNo);
		$.ajax({
			async : false,
			cache : false,
			type : 'post',
			dataType : "json",
			data : {'pageNo':pageNo,'pageSize':5},
			url : 'usercenter/read_list' ,// 请求的action路径
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				layer.msg("请求失败！");
			},
			success : function(data) {
				if(data.state=="9003"){
					layer.msg("没有权限！");
					return ;
				}else if(data.state=="9002"){
					layer.msg("请重新登录！");
					top.location.reload();
					return ;
				}
					var list = data.list;
					var strHtml = "";
					for(var i=0;i<list.length;i++){
						strHtml +='<tr><td>'+list[i].dname+'</td>'+
							'<td><a class="btn btn-primary" onclick="playVedio(\''+list[i].url+'\')">播放</a></td>'+
							'<td>'+list[i].watchtimes+'</td>'+
							'<td>'+list[i].readdate+'</td>'+
							'<td><a class="btn btn-primary" target="_blank" href="'+list[i].url+'">下载</a>&nbsp;'+
							'<a class="btn btn-danger" href="javascript:void(0);"onclick="deleteItem('+list[i].id+')">删除</a></td></tr>';
					}
					if(list.length==0){
						strHtml = "<tr style=\"text-align:center;\"><td colspan=\"4\">找不到素材信息！</td></tr>";
					}
					$("#list").html(strHtml);
					$(".tcdPageCode").html(pageInfo(data.totalPage,data.pageNumber));
			}
		});	
}
  function deleteItem(id){
	  layer.confirm('你确定要删除吗?', {
 		  title:'删除',
 		  btn: ['确定','取消'] //按钮
 		}, function(){  
  			$.ajax({
				async : false,
				cache : false,
				type : 'post',
				dataType : "json",
				url : 'usercenter/delete_read?id='+id ,// 请求的action路径
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					layer.msg("请求失败！");
				},
				success : function(data) {
					if(data.state=="9003"){
						layer.msg("没有权限！");
						return ;
					}else if(data.state=="9002"){
						layer.msg("请重新登录！");
						top.location.reload();
						return ;
					}
					if(data){
						layer.msg("删除成功！");
						window.location.reload();
					}else{
						layer.msg("删除失败！");
					}
				}
			});	
 		}, function(){
  		});
  }
	</script>
</body>
</html>